package com.woniuxy.controller;

import com.woniuxy.entity.ShopCategories;
import com.woniuxy.service.ShopCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
//import org.springframework.http.ResponseResult;
import com.woniuxy.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;


/**
 * (ShopCategories)表控制层
 *
 * @author makejava
 * @since 2025-07-10 11:54:53
 */
@RestController
@RequestMapping("shopCategories")
public class ShopCategoriesController {
    /**
     * 服务对象
     */
    @Autowired
    private ShopCategoriesService shopCategoriesService;

    /**
     * 分页查询
     *
     * @param shopCategories 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseResult<Page<ShopCategories>> queryByPage(ShopCategories shopCategories, PageRequest pageRequest) {
        return ResponseResult.success(this.shopCategoriesService.queryByPage(shopCategories, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<ShopCategories> queryById(@PathVariable("id") Long id) {
        return ResponseResult.success(this.shopCategoriesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param shopCategories 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseResult<ShopCategories> add(ShopCategories shopCategories) {
        return ResponseResult.success(this.shopCategoriesService.insert(shopCategories));
    }

    /**
     * 编辑数据
     *
     * @param shopCategories 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult<ShopCategories> edit(ShopCategories shopCategories) {
        return ResponseResult.success(this.shopCategoriesService.update(shopCategories));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Long id) {
        return ResponseResult.success(this.shopCategoriesService.deleteById(id));
    }

}

